﻿using Microsoft.AspNetCore.Mvc;
using MongdbHelper;
using MongoDB.Driver;
using PerformanceBll;
using PerformanceBll.Model;
using System.Collections.Generic;

namespace PerformanceTest.Controllers
{
    public class EchartController : Controller
    {
        public string connstr = "mongodb://admin:adminlinux@52.83.104.122:30000,52.83.216.230:30000/";
        public string db = "Chart";
        public IActionResult Index()
        {

            var info = new LinuxSSH().GetCpuMemary();
            ViewBag.data = info;
            return View();

        }
        public IActionResult Deskp()
        {
            return View();
        }
        public IActionResult Deskp2()
        {
            return View();
        }
        public ActionResult GetEchartData()
        {

            var reslut = new List<dynamic>();
            var list = new List<Chartmodel>();
            dynamic obj = new
            {
                Key = "分片A",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "dzconcurrent_a").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj1 = new
            {
                Key = "分片B",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "dzconcurrent_b").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj2 = new
            {
                Key = "Mongos路由",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "dzconcurrent_config").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj3 = new
            {
                Key = "Config配置",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "dzconcurrent_mongos").GetAll<Chartmodel>(x => true).ToList()
            };

            reslut.Add(obj);
            reslut.Add(obj1);
            reslut.Add(obj2);
            reslut.Add(obj3);
            return Json(reslut);
        }
        public ActionResult GetEchartData2()
        {

            var reslut = new List<dynamic>();
            var list = new List<Chartmodel>();
            dynamic obj = new
            {
                Key = "分片A",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "hxconcurrent" + "_a").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj1 = new
            {
                Key = "分片B",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "hxconcurrent" + "_b").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj2 = new
            {
                Key = "Mongos路由",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "hxconcurrent" + "_config").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj3 = new
            {
                Key = "Config配置",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "hxconcurrent" + "_mongos").GetAll<Chartmodel>(x => true).ToList()
            };

            reslut.Add(obj);
            reslut.Add(obj1);
            reslut.Add(obj2);
            reslut.Add(obj3);
            return Json(reslut);
        }
        public ActionResult GetEchartData3()
        {

            var reslut = new List<dynamic>();
            var list = new List<Chartmodel>();
            dynamic obj = new
            {
                Key = "分片A",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "dzsingle" + "_a").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj1 = new
            {
                Key = "分片B",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "dzsingle" + "_b").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj2 = new
            {
                Key = "Mongos路由",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "dzsingle" + "_config").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj3 = new
            {
                Key = "Config配置",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "dzsingle" + "_mongos").GetAll<Chartmodel>(x => true).ToList()
            };

            reslut.Add(obj);
            reslut.Add(obj1);
            reslut.Add(obj2);
            reslut.Add(obj3);
            return Json(reslut);
        }
        public ActionResult GetEchartData4()
        {

            var reslut = new List<dynamic>();
            var list = new List<Chartmodel>();
            dynamic obj = new
            {
                Key = "分片A",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "hxsingle" + "_a").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj1 = new
            {
                Key = "分片B",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "hxsingle" + "_b").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj2 = new
            {
                Key = "Mongos路由",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "hxsingle" + "_config").GetAll<Chartmodel>(x => true).ToList()
            };
            dynamic obj3 = new
            {
                Key = "Config配置",
                Value = 124,
                Data = new MongoDBHelper(connstr, db, "hxsingle" + "_mongos").GetAll<Chartmodel>(x => true).ToList()
            };

            reslut.Add(obj);
            reslut.Add(obj1);
            reslut.Add(obj2);
            reslut.Add(obj3);
            return Json(reslut);
        }
    }
}